﻿using System.Text.RegularExpressions;

namespace ReverseOrder;

internal class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("输入文件夹路径");
        string inputFolder = Console.ReadLine(); // 输入文件夹路径
        Console.WriteLine("输出文件夹路径");
        string outputFolder = Console.ReadLine(); // 输出文件夹路径

        if (!Directory.Exists(outputFolder))
        {
            Directory.CreateDirectory(outputFolder);
        }

        var files = Directory.GetFiles(inputFolder, "crop*.png");

        var sortedFiles = files
            .Select(file => new
            {
                FilePath = file,
                Index = int.Parse(Regex.Match(Path.GetFileNameWithoutExtension(file), @"\d+").Value)
            })
            .OrderByDescending(file => file.Index)
            .ToList();

        for (int i = 0; i < sortedFiles.Count; i++)
        {
            string inputFile = sortedFiles[i].FilePath;
            string outputFile = Path.Combine(outputFolder, $"reversed{i + 1}.png");

            File.Copy(inputFile, outputFile, true);
            Console.WriteLine(sortedFiles[i].FilePath);
            Console.WriteLine(i);
        }

        Console.WriteLine("文件排序反向完成！");
    }
}
